package com.ruoyi.controller.fanruan;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.domain.jpjs.common.fanruan.SkFirst;
import com.ruoyi.service.fanruan.ISkFirstService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 商开集团Controller
 *
 * @author ruoyi
 * @date 2020-11-04
 */
@Controller
@RequestMapping("/fanruan/sk")
public class SkFirstController extends BaseController
{
    private String prefix = "fanruan/sk";

    @Autowired
    private ISkFirstService skFirstService;

    @RequiresPermissions("fanruan:sk:view")
    @GetMapping()
    public String sk()
    {
        return "fanruan/sk/sk";
    }

    /**
     * 查询商开集团列表
     */
    @RequiresPermissions("fanruan:sk:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(SkFirst skFirst)
    {
        startPage();
        List<SkFirst> list = skFirstService.selectSkFirstList(skFirst);
        return getDataTable(list);
    }

    /**
     * 导出商开集团列表
     */
    @RequiresPermissions("fanruan:sk:export")
    @Log(title = "商开集团", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(SkFirst skFirst)
    {
        List<SkFirst> list = skFirstService.selectSkFirstList(skFirst);
        ExcelUtil<SkFirst> util = new ExcelUtil<SkFirst>(SkFirst.class);
        return util.exportExcel(list, "sk");
    }

    /**
     * 新增商开集团
     */
    @GetMapping("/add")
    public String add()
    {
        return "fanruan/sk/add";
    }

    /**
     * 新增保存商开集团
     */
    @RequiresPermissions("fanruan:sk:add")
    @Log(title = "商开集团", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(SkFirst skFirst)
    {
        return toAjax(skFirstService.insertSkFirst(skFirst));
    }

    /**
     * 修改商开集团
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        SkFirst skFirst = skFirstService.selectSkFirstById(id);
        mmap.put("skFirst", skFirst);
        return "fanruan/sk/edit";
    }

    /**
     * 修改保存商开集团
     */
    @RequiresPermissions("fanruan:sk:edit")
    @Log(title = "商开集团", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(SkFirst skFirst)
    {
        return toAjax(skFirstService.updateSkFirst(skFirst));
    }

    /**
     * 删除商开集团
     */
    @RequiresPermissions("fanruan:sk:remove")
    @Log(title = "商开集团", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(skFirstService.deleteSkFirstByIds(ids));
    }
}
